package com.wss.lsl.test.driven.arithmetic.sort;

/**
 * 排序工具
 * 
 * @author Administrator
 * 
 */
public class SortUtils {

	/**
	 * 快速排序算法
	 * 
	 * @param data
	 * @param low
	 * @param up
	 */
	public static void quicklySort(int[] data, int low, int up) {
		if (low >= up) {
			return;
		}
		int t = data[low], i = low, j = up + 1;
		while (true) {
			do {
				i++;
			} while (i <= up && data[i] < t);
			do {
				j--;
			} while (data[j] > t);
			if (i > j) {
				break;
			}
			// i,j 数据交换位置
			int temp = data[i];
			data[i] = data[j];
			data[j] = temp;
		}
		// low,j 交换位置
		data[low] = data[j];
		data[j] = t;
		quicklySort(data, low, j - 1);
		quicklySort(data, j + 1, up);
	}
}
